package com.suray.basic.wcs.plc.pojo.oper;

import com.suray.basic.wcs.plc.core.PlcOffset;
import com.suray.basic.wcs.plc.enums.Location;
import com.suray.basic.wcs.plc.enums.PlcDeviceType;
import com.suray.basic.wcs.plc.pojo.DeviceBase;
import com.suray.basic.wcs.utils.Coord;

/**
 * 按钮
 */
public class ButtonOper extends DeviceBase {

    private boolean interrupt;

    /**
     * 按钮状态
     */
    private static final PlcOffset BUTTON = new PlcOffset(0, null);

    public ButtonOper(PlcDeviceType plcDeviceType, int startNo, String deviceName, int deviceNo, Coord coord,
                      Location location, Coord lockLocation, long deviceId, Integer gridzMax, Integer gridzRelative,
                      int plcId) {
        super(plcDeviceType, startNo, deviceName, deviceNo, coord, location, lockLocation,deviceId,gridzMax,
                gridzRelative, plcId);
        interrupt = false;
    }

    /**
     * 是否有入库信号
     * @return
     */
    public boolean isInSignal() {
        return readPlc(BUTTON) == 1;
    }

    /**
     * 检测中断
     */
    public void interrupt() {
        if (interrupt) {
            throw new RuntimeException(getDeviceName() + "事件中断");
        }
    }

    /**
     * 清除中断
     */
    public void clearInterrupt() {
        interrupt = false;
    }

    /**
     * 设置中断
     */
    public void setInterrupt() {
        interrupt = true;
    }
}
